From 310781ecdd573c299e536ab0070910c484aa23d7 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 11 Oct 2015 16:48:08 -0400 Subject: [PATCH] gtk-demo: Add a GtkShortcutsWindow demo This example implements the mockups from the help overlay design, showing off the various features of GtkShortcutsWindow. --- demos/gtk-demo/Makefile.am | 1 + demos/gtk-demo/demo.gresource.xml | 11 + .../gesture-two-finger-swipe-left.svg | 173 +++++++ .../gesture-two-finger-swipe-right.svg | 169 +++++++ demos/gtk-demo/shortcuts-builder.ui | 454 ++++++++++++++++++ demos/gtk-demo/shortcuts-clocks.ui | 148 ++++++ demos/gtk-demo/shortcuts-gedit.ui | 181 +++++++ demos/gtk-demo/shortcuts.c | 92 ++++ demos/gtk-demo/shortcuts.ui | 44 ++ 9 files changed, 1273 insertions(+) create mode 100644 demos/gtk-demo/gesture-two-finger-swipe-left.svg create mode 100644 demos/gtk-demo/gesture-two-finger-swipe-right.svg create mode 100644 demos/gtk-demo/shortcuts-builder.ui create mode 100644 demos/gtk-demo/shortcuts-clocks.ui create mode 100644 demos/gtk-demo/shortcuts-gedit.ui create mode 100644 demos/gtk-demo/shortcuts.c create mode 100644 demos/gtk-demo/shortcuts.ui diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am index fc1cae43cc..e93a45091d 100644 --- a/demos/gtk-demo/Makefile.am +++ b/demos/gtk-demo/Makefile.am @@ -56,6 +56,7 @@ demos_base = \ scale.c \ search_entry.c \ search_entry2.c \ + shortcuts.c \ sidebar.c \ sizegroup.c \ spinbutton.c \ diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml index a3a3455577..a19028bf86 100644 --- a/demos/gtk-demo/demo.gresource.xml +++ b/demos/gtk-demo/demo.gresource.xml @@ -91,6 +91,12 @@ stack.ui + + shortcuts.ui + shortcuts-builder.ui + shortcuts-gedit.ui + shortcuts-clocks.ui + revealer.ui @@ -163,6 +169,7 @@ scale.c search_entry.c search_entry2.c + shortcuts.c sizegroup.c sidebar.c stack.c @@ -213,4 +220,8 @@ modelbutton.ui + + gesture-two-finger-swipe-right.svg + gesture-two-finger-swipe-left.svg + diff --git a/demos/gtk-demo/gesture-two-finger-swipe-left.svg b/demos/gtk-demo/gesture-two-finger-swipe-left.svg new file mode 100644 index 0000000000..d93af46a19 --- /dev/null +++ b/demos/gtk-demo/gesture-two-finger-swipe-left.svg @@ -0,0 +1,173 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/gtk-demo/gesture-two-finger-swipe-right.svg b/demos/gtk-demo/gesture-two-finger-swipe-right.svg new file mode 100644 index 0000000000..758656806c --- /dev/null +++ b/demos/gtk-demo/gesture-two-finger-swipe-right.svg @@ -0,0 +1,169 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/gtk-demo/shortcuts-builder.ui b/demos/gtk-demo/shortcuts-builder.ui new file mode 100644 index 0000000000..f6777e208b --- /dev/null +++ b/demos/gtk-demo/shortcuts-builder.ui @@ -0,0 +1,454 @@ + + + + + + resource:///icons/gesture-two-finger-swipe-left.svg + + + resource:///icons/gesture-two-finger-swipe-right.svg + + + + 1 + + + 1 + editor + Editor Shortcuts + + + 1 + General + + + 1 + Global Search + <ctrl>period + + + + + 1 + Preferences + <ctrl>comma + + + + + 1 + Command Bar + <ctrl>Return + + + + + 1 + Terminal + <ctrl><shift>t + + + + + 1 + Keyboard Shortcuts + <ctrl><shift>question + + + + + + + 1 + Panels + + + 1 + Toggle left panel + F9 + + + + + 1 + Toggle right panel + <shift>F9 + + + + + 1 + Toggle bottom panel + <ctrl>F9 + + + + + + + 1 + Touchpad gestures + + + 1 + Switch to the next document + Two finger swipe right + right-swipe-icon + + + + + 1 + Switch to the previous document + Two finger swipe left + left-swipe-icon + + + + + + + 1 + Files + + + 1 + <ctrl>n + Create new document + + + + + 1 + <ctrl>o + Open a document + + + + + 1 + <ctrl>s + Save the document + + + + + 1 + <ctrl>w + Close the document + + + + + 1 + <ctrl><alt>Page_Down + Switch to the next document + + + + + 1 + <ctrl><alt>Page_Up + Switch to the previous document + + + + + + + 1 + Find and replace + + + 1 + <ctrl>f + Find + + + + + 1 + <ctrl>g + Find the next match + + + + + 1 + <ctrl><shift>g + Find the previous match + + + + + 1 + <ctrl><shift>k + Clear highlight + + + + + + + 1 + Copy and Paste + + + 1 + <ctrl>c + Copy selected text to clipboard + + + + + 1 + <ctrl>x + Cut selected text to clipboard + + + + + 1 + <ctrl>v + Paste text from clipboard + + + + + + + 1 + Undo and Redo + + + 1 + <ctrl>z + Undo previous command + + + + + 1 + <ctrl><shift>z + Redo previous command + + + + + + + 1 + Editing + + + 1 + <ctrl><shift>a + Increment number at cursor + + + + + 1 + <ctrl><shift>x + Decrement number at cursor + + + + + 1 + <ctrl>j + Join selected lines + + + + + 1 + <ctrl>space + Show completion window + + + + + 1 + Insert + Toggle overwrite + + + + + 1 + <ctrl><alt>i + Reindent line + + + + + + + 1 + Navigation + + + 1 + <alt>n + Move to next error in file + + + + + 1 + <alt>p + Move to previous error in file + + + + + 1 + <shift><alt>Left + Move to previous edit location + + + + + 1 + <shift><alt>Right + Move to next edit location + + + + + 1 + <alt>period + Jump to definition of symbol + + + + + 1 + <alt><shift>Up + Move sectionport up within the file + + + + + 1 + <alt><shift>Down + Move sectionport down within the file + + + + + 1 + <alt><shift>End + Move sectionport to end of file + + + + + 1 + <alt><shift>Home + Move sectionport to beginning of file + + + + + 1 + <ctrl>percent + Move to matching bracket + + + + + + + 1 + Selections + + + 1 + <ctrl>a + Select all + + + + + 1 + <ctrl>backslash + Unselect all + + + + + + + + + 1 + terminal + Terminal Shortcuts + + + 1 + General + + + 1 + Global Search + <ctrl>period + + + + + 1 + Preferences + <ctrl>comma + + + + + 1 + Command Bar + <ctrl>Return + + + + + 1 + Terminal + <ctrl><shift>t + + + + + 1 + Keyboard Shortcuts + <ctrl><shift>question + + + + + + + 1 + Copy and Paste + + + 1 + <ctrl><shift>c + Copy selected text to clipboard + + + + + 1 + <ctrl><shift>v + Paste text from clipboard + + + + + + + + + diff --git a/demos/gtk-demo/shortcuts-clocks.ui b/demos/gtk-demo/shortcuts-clocks.ui new file mode 100644 index 0000000000..051a4c2bae --- /dev/null +++ b/demos/gtk-demo/shortcuts-clocks.ui @@ -0,0 +1,148 @@ + + + + + + 1 + + + 1 + shortcuts + 10 + + + 1 + General + + + 1 + <ctrl>Page_Down + Go to the next section + + + + + 1 + <ctrl>Page_Up + Go to the previous section + + + + + 1 + <alt>Q + Quit + + + + + 1 + <alt>Left + Forward + + + + + 1 + <ctrl>Right + Back + + + + + + + 1 + world + World Clocks + + + 1 + <ctrl>N + Add a world clock + + + + + 1 + <ctrl>S + Select world clocks + + + + + + + 1 + alarm + Alarm + + + 1 + <ctrl>N + Add an alarm + + + + + 1 + <ctrl>S + Select alarms + + + + + + + 1 + stopwatch + Stopwatch + + + 1 + Return space + Start / Stop / Continue + + + + + 1 + L + Lap + + + + + 1 + Delete + Reset + + + + + + + 1 + timer + Timer + + + 1 + Return space + Start / Stop / Pause + + + + + 1 + Delete + Reset + + + + + + + + + diff --git a/demos/gtk-demo/shortcuts-gedit.ui b/demos/gtk-demo/shortcuts-gedit.ui new file mode 100644 index 0000000000..74bd2dcf93 --- /dev/null +++ b/demos/gtk-demo/shortcuts-gedit.ui @@ -0,0 +1,181 @@ + + + + + + resource:///icons/gesture-two-finger-swipe-left.svg + + + resource:///icons/gesture-two-finger-swipe-right.svg + + + + 1 + + + 1 + shortcuts + 12 + + + 1 + Touchpad gestures + + + 1 + Switch to the next document + Two finger swipe right + right-swipe-icon + + + + + 1 + Switch to the previous document + Two finger swipe left + left-swipe-icon + + + + + + + 1 + Documents + + + 1 + <ctrl>N + Create new document + + + + + 1 + <ctrl>O + Open a document + + + + + 1 + <ctrl>S + Save the document + + + + + 1 + <ctrl>W + Close the document + + + + + 1 + <ctrl><Alt>Page_Down + Switch to the next document + + + + + 1 + <ctrl><Alt>Page_Up + Switch to the previous document + + + + + + + 1 + Find and Replace + + + 1 + <ctrl>F + Find + + + + + 1 + <ctrl>G + Find the next match + + + + + 1 + <ctrl><Shift>G + Find the previous match + + + + + 1 + <ctrl>H + Find and Replace + + + + + 1 + <ctrl><Shift>K + Clear highlight + + + + + 1 + <ctrl>I + Go to line + + + + + + + 1 + Tools + + + 1 + <shift>F7 + Check spelling + + + + + + + 1 + Miscellaneous + + + 1 + F11 + Fullscreen on / off + + + + + 1 + <ctrl>P + Print the document + + + + + 1 + Insert + Toggle insert / overwrite + + + + + + + + + diff --git a/demos/gtk-demo/shortcuts.c b/demos/gtk-demo/shortcuts.c new file mode 100644 index 0000000000..69f44c6e43 --- /dev/null +++ b/demos/gtk-demo/shortcuts.c @@ -0,0 +1,92 @@ +/* Shortcuts Window + * + * GtkShortcutsWindow is a window that provides a help overlay + * for shortcuts and gestures in an application. + */ + +#include + +static void +show_shortcuts (GtkWidget *window, + const gchar *id, + const gchar *view) +{ + GtkBuilder *builder; + GtkWidget *overlay; + gchar *path; + + path = g_strdup_printf ("/shortcuts/%s.ui", id); + builder = gtk_builder_new_from_resource (path); + g_free (path); + overlay = GTK_WIDGET (gtk_builder_get_object (builder, id)); + gtk_window_set_transient_for (GTK_WINDOW (overlay), GTK_WINDOW (window)); + g_object_set (overlay, "view-name", view, NULL); + gtk_widget_show (overlay); +} + +static void +builder_shortcuts (GtkWidget *window) +{ + show_shortcuts (window, "shortcuts-builder", NULL); +} + +static void +gedit_shortcuts (GtkWidget *window) +{ + show_shortcuts (window, "shortcuts-gedit", NULL); +} + +static void +clocks_shortcuts (GtkWidget *window) +{ + show_shortcuts (window, "shortcuts-clocks", NULL); +} + +static void +clocks_shortcuts_stopwatch (GtkWidget *window) +{ + show_shortcuts (window, "shortcuts-clocks", "stopwatch"); +} + +GtkWidget * +do_shortcuts (GtkWidget *do_widget) +{ + static GtkWidget *window = NULL; + static gboolean icons_added = FALSE; + + if (!icons_added) + { + icons_added = TRUE; + gtk_icon_theme_add_resource_path (gtk_icon_theme_get_default (), "/icons"); + } + + g_type_ensure (G_TYPE_FILE_ICON); + + if (!window) + { + GtkBuilder *builder; + + builder = gtk_builder_new_from_resource ("/shortcuts/shortcuts.ui"); + gtk_builder_add_callback_symbols (builder, + "builder_shortcuts", G_CALLBACK (builder_shortcuts), + "gedit_shortcuts", G_CALLBACK (gedit_shortcuts), + "clocks_shortcuts", G_CALLBACK (clocks_shortcuts), + "clocks_shortcuts_stopwatch", G_CALLBACK (clocks_shortcuts_stopwatch), + NULL); + gtk_builder_connect_signals (builder, NULL); + window = GTK_WIDGET (gtk_builder_get_object (builder, "window1")); + gtk_window_set_screen (GTK_WINDOW (window), + gtk_widget_get_screen (do_widget)); + g_signal_connect (window, "destroy", + G_CALLBACK (gtk_widget_destroyed), &window); + + g_object_unref (builder); + } + + if (!gtk_widget_get_visible (window)) + gtk_widget_show_all (window); + else + gtk_widget_destroy (window); + + return window; +} diff --git a/demos/gtk-demo/shortcuts.ui b/demos/gtk-demo/shortcuts.ui new file mode 100644 index 0000000000..da480c78ab --- /dev/null +++ b/demos/gtk-demo/shortcuts.ui @@ -0,0 +1,44 @@ + + + + + + Shortcuts + + + 1 + vertical + 50 + 10 + + + 1 + Builder + + + + + + 1 + GEdit + + + + + + 1 + Clocks - All + + + + + + 1 + Clocks - Stopwatch + + + + + + + -- 2.30.2